package com.beauty.payment.controller;

import com.beauty.payment.dto.PaymentRequest;
import com.beauty.payment.dto.PaymentResponse;
import com.beauty.payment.entity.Payment;
import com.beauty.payment.result.Result;
import com.beauty.payment.service.PaymentService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/payment")
@RequiredArgsConstructor
public class PaymentController {
    
    private final PaymentService paymentService;
    
    @PostMapping
    public Result<PaymentResponse> createPayment(@Valid @RequestBody PaymentRequest paymentRequest) {
        return Result.success(paymentService.createPayment(paymentRequest));
    }
    
    @GetMapping("/{id}")
    public Result<PaymentResponse> getPaymentById(@PathVariable Long id) {
        return Result.success(paymentService.getPaymentById(id));
    }
    
    @GetMapping("/order/{orderId}")
    public Result<List<PaymentResponse>> getPaymentsByOrderId(@PathVariable String orderId) {
        return Result.success(paymentService.getPaymentsByOrderId(orderId));
    }
    
    @GetMapping("/customer/{customerId}")
    public Result<List<PaymentResponse>> getPaymentsByCustomerId(@PathVariable String customerId) {
        return Result.success(paymentService.getPaymentsByCustomerId(customerId));
    }
    
    @GetMapping
    public Result<List<PaymentResponse>> getAllPayments() {
        return Result.success(paymentService.getAllPayments());
    }
    
    @PutMapping("/{id}/status")
    public Result<PaymentResponse> updatePaymentStatus(
            @PathVariable Long id, 
            @RequestParam Payment.PaymentStatus status) {
        return Result.success(paymentService.updatePaymentStatus(id, status));
    }
    
    @DeleteMapping("/{id}")
    public Result<Void> deletePayment(@PathVariable Long id) {
        paymentService.deletePayment(id);
        return Result.success();
    }
} 